package com.um.springboot.starter.utils;


import java.util.Date;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @author 邓南辉
 * 日期 2022/4/22
 * 版权所有 广州优匠科技有限公司
 */
public class GuidUtil {

    public static String randomNumbers(int length) {
        return randomString("0123456789", length);
    }

    public static ThreadLocalRandom getRandom() {
        return ThreadLocalRandom.current();
    }

    public static int randomInt(int limit) {
        return getRandom().nextInt(limit);
    }

    public static String randomString(String baseString, int length) {
        if (StringUtil.isEmpty(baseString)) {
            return "";
        } else {
            StringBuilder sb = new StringBuilder(length);
            if (length < 1) {
                length = 1;
            }

            int baseLength = baseString.length();

            for(int i = 0; i < length; ++i) {
                int number = randomInt(baseLength);
                sb.append(baseString.charAt(number));
            }

            return sb.toString();
        }
    }


    public static String getGuid() {
        return DateUtil.getDateString(new Date(),"yyMMddHHmmssSSS") + randomNumbers(4);
    }
}
